﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using GENERIC.Respository.Interfaces;

namespace GENERIC.LinqToSqlRepository
{
    public class LinqToSqlSet<T> : IGENERICSet<T> where T : class, new()
    {
        #region Constructor

        public LinqToSqlSet(Table<T> table)
        {
            Table = table;
        }

        #endregion

        #region Properties

        private Table<T> Table { get; set; }

        #endregion


        public void Insert(T entity)
        {
            Table.InsertOnSubmit(entity);
        }

        public void Update(T entity)
        {
            Table.Attach(entity, true);
        }

        public void Delete(T entity)
        {
            Table.DeleteOnSubmit(entity);
        }

        public IQueryable<T> Get()
        {
            return Table;
        }
    }
}
